#include "FreeRTOS.h"
#include "task.h"
#include "main.h"
#include "cmsis_os2.h"
#include "user_queue.h"

/* Definitions for myQueue01 */
osMessageQueueId_t myQueue01Handle;
const osMessageQueueAttr_t myQueue01_attributes = { .name = "myQueue01" };
/* Definitions for myQueue02 */
osMessageQueueId_t myQueue02Handle;
const osMessageQueueAttr_t myQueue02_attributes = { .name = "myQueue02" };

void RingBuffIni(RingBuff *pbuff)
{
	pbuff->head = 0;
	pbuff->tail = 0;
	pbuff->lenght = 0;
}

uint8_t Read_RingBuff(RingBuff *pbuff, DataBuff *rdata)
{
	if (pbuff->lenght == 0)
		return 1;
	*rdata = pbuff->data_buff[pbuff->head];
	pbuff->head = (pbuff->head + 1) % ringbuff_len;
	pbuff->lenght--;
	return 0;
}

uint8_t Write_RingBuff(RingBuff *pbuff, uint8_t *buf, uint8_t len)
{
	if ((pbuff->lenght >= ringbuff_len) || !len)
		return 1;
	pbuff->data_buff[pbuff->tail].len = len;
	for (int i = 0; i < len; i++)
		pbuff->data_buff[pbuff->tail].data[i] = buf[i];
	pbuff->tail = (pbuff->tail + 1) % ringbuff_len;
	pbuff->lenght++;
	return 0;
}
